import { Component, Vue, Inject } from 'vue-property-decorator';

import { IContentType } from '@/shared/model/content-type.model';
import ContentTypeService from './content-type.service';

@Component
export default class ContentTypeDetails extends Vue {
  @Inject('contentTypeService') private contentTypeService: () => ContentTypeService;
  public contentType: IContentType = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.contentTypeId) {
        vm.retrieveContentType(to.params.contentTypeId);
      }
    });
  }

  public retrieveContentType(contentTypeId) {
    this.contentTypeService()
      .find(contentTypeId)
      .then(res => {
        this.contentType = res;
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
